﻿using MiniExcelLibs;
using MiniExcelLibs.Attributes;

namespace Ongoal.Quotation.Service.Common
{
    public class ExcelOptionDeal
    {
        public List<Exceldescribe> GetExcelData(string path, string DbName, int TagType)
        {

            using (var stream = File.OpenRead(path))
            {
                if (TagType == 1)
                {
                    var rows = stream.Query<Exceldescribe>(startCell: "F3").Where(z => z.PlcCode == DbName && (z.TagType == TagType || z.TagType == 3)).ToList();
                    return rows;
                }
                else
                {
                    var rows = stream.Query<Exceldescribe>(startCell: "F3").Where(z => z.PlcCode == DbName && z.TagType == TagType).ToList();
                    return rows;
                }
            }
        }

        public string GetTempPath(string FileName = "Temp")
        {
            string dic = Directory.GetCurrentDirectory() + "/" + FileName + "/" + DateTime.Now.ToString("yyyyMM");
            if (!Directory.Exists(dic))
                Directory.CreateDirectory(dic);
            return dic;
        }
    }
    public class Exceldescribe
    {

        [ExcelColumnName("IP地址")]
        public string IP { get; set; }
        [ExcelColumnName("区号")]
        public string PlcCode { get; set; }
        [ExcelColumnName("测量地址")]
        public string Addr { get; set; }
        [ExcelColumnName("位内地址")]
        public string AddrInByte { get; set; }
        [ExcelColumnName("测量项目")]
        public string MeasureItem { get; set; }
        [ExcelColumnName("单位")]
        public string Dw { get; set; }
        [ExcelColumnName("数据特点")]
        public int TagType { get; set; }
        [ExcelColumnName("数据类型")]
        public string DataType { get; set; }
        [ExcelColumnName("分组")]
        public int Group { get; set; }
    }
}
